package com.mygenostics.bo;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

public class Service1 extends GenoService {
	
	private static final String LIBRARY_CONSTRUCT = "Library Construct";
	private static final String SOLEXA_LANE = "Solexa Sequenceing lanes";
	
	public Service1() {
		this.basicPrice = new BigDecimal(1200);
		this.promotedPrice = new BigDecimal(700);
		this.serviceName = "Customized DNA target enrichment";
		SubService basicService = new SubService();
		basicService.number = 1;
		basicService.subSrvName = "Basic service";
		basicService.subSrvPrice = new BigDecimal(1200);
		this.services.put(basicService.subSrvName, basicService);
	}
	

	@Override
	public BigDecimal getTotalPrice() {
		BigDecimal total = this.basicPrice;
		
		Collection<SubService> col = services.values();
		
		Iterator<SubService> it  = col.iterator();
		
		if (it.hasNext()) {
			SubService s = it.next();
			// total += s.subSrvPrice * s.number;
			total = total.add(s.subSrvPrice.multiply(new BigDecimal(s.number)));
		}
		
		return total;
	}

	@Override
	public ArrayList<SubService> getListedServices() {
		ArrayList<SubService> list = new ArrayList<SubService>();
		
		Collection<SubService> col = services.values();
		
		Iterator<SubService> it  = col.iterator();
		
		if (it.hasNext()) {
			list.add(it.next());
		}
		
		Collections.sort(list);
		
		return list;
	}
	
	public void updateLibraryConstruction(int number) {
		if (number == 0) {
			this.services.remove(LIBRARY_CONSTRUCT);
		}
		else {
			SubService s = this.services.get(LIBRARY_CONSTRUCT);
			
			if (s == null) {
				s = new SubService();
				s.subSrvName = LIBRARY_CONSTRUCT;
				s.subSrvPrice = new BigDecimal(200);
				s.order = 1;
				s.removable = true;
			}
			
			s.number  = number;
			
			services.put(LIBRARY_CONSTRUCT, s);
		}
	}
	
	public void updateSolexaSequence(int number) {
		if (number == 0) {
			this.services.remove(SOLEXA_LANE);
		}
		else {
			SubService s = this.services.get(SOLEXA_LANE);
			
			if (s == null) {
				s = new SubService();
				s.subSrvName = SOLEXA_LANE;
				s.subSrvPrice = new BigDecimal(1000);
				s.order = 2;
				s.removable = true;
			}
			
			s.number  = number;
			
			services.put(SOLEXA_LANE, s);
		}
	}

}
